package com.example.administrator.myapplication;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.example.administrator.myapplication.adapter.Myadapter;
import com.example.administrator.myapplication.fragment.Fragment1;
import com.example.administrator.myapplication.fragment.Fragment2;
import com.example.administrator.myapplication.fragment.Fragment3;
import com.example.administrator.myapplication.fragment.Fragment4;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();
    }
    //第一步 设置基本布局 使用 viewpager  控件
    //第二步创建好fragment
    //第三步 创建viewpager适配器
    //第四步 将 fragment添加到适配器上
    private void initView(){

        viewPager = (ViewPager) findViewById(R.id.viewpager);
        Fragment1 fragment1 = new Fragment1();
        Fragment2 fragment2 = new Fragment2();
        Fragment3 fragment3 = new Fragment3();
        Fragment4 fragment4 = new Fragment4();
        ArrayList arrayList = new ArrayList();
        arrayList.add(fragment1);
        arrayList.add(fragment2);
        arrayList.add(fragment3);
        arrayList.add(fragment4);
        viewPager.setAdapter(new Myadapter(getSupportFragmentManager(),MainActivity.this,arrayList));
    }
    private void initData(){

    }
    private void initEvent(){

    }
}
